package com.gin.kotlin.no_gay_alliance.database.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.gin.kotlin.no_gay_alliance.database.entity.NoticeMsg

@Dao
interface NoticeMsgDao {
    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun add(ngaAccount: NoticeMsg)

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    fun add(ngaAccount: List<NoticeMsg>)

    /**
     * 设置为已读
     * @param uuid String
     */
    @Query("update NoticeMsg set unread = 0 where uuid=:uuid")
    fun read(uuid: String)

    /**
     * 全部已读
     * @param userId Long
     */
    @Query("update NoticeMsg set unread = 0 where userId=:userId")
    fun read(userId: Long)



    /**
     * 按用户查询
     * @param userId Long
     * @return List<NoticeMsg>
     */
    @Query("select * from NoticeMsg where userId=:userId")
    fun list(userId: Long): List<NoticeMsg>

    /**
     * 按用户查询清空
     * @param userId Long
     */
    @Query("delete from NoticeMsg where userId=:userId")
    fun clear(userId: Long)

    /**
     * 删除单条
     * @param uuid String
     */
    @Query("delete from NoticeMsg where uuid=:uuid")
    fun delete(uuid: String)
}